package com.example.test1.controller;

import com.example.test1.service.UserService;
import com.example.test1.bean.UserBean;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
public class LoginController {
    @Resource
    UserService userService;
    @RequestMapping("/login")
    public String login() {
        return "login";
    }

    @RequestMapping(value = "/loginDo", method = RequestMethod.POST)
    public String loginDo(String name, String password, HttpSession session) {
        UserBean userBean = userService.loginIn(name, password);
        if (userBean != null) {
            session.setAttribute("user", "userBean");
            return "success";
        } else {
            return "error";

        }
    }
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "index";
    }
}
